﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace TestGenerator
{
    static class Settings
    {
        private static string inputFilePath;
        private static string outputFileName;
        private static string answersFile;
        private static int numberOfTests;
        private static int questionCount;
        private static int answersCount;

#region Properties
        public static string InputFilePath
        {
            get
            {
                return inputFilePath;
            }
        }

        public static string OutputFileName
        {
            get
            {
                return outputFileName;
            }
        }

        public static string AnswersFile
        {
            get
            {
                return answersFile;
            }
        }

        public static int NumberOfTests
        {
            get
            {
                return numberOfTests;
            }
        }

        public static int QuestionCount
        {
            get
            {
                return questionCount;
            }
        }

        public static int AnswersCount
        {
            get
            {
                return answersCount;
            }
        }
#endregion

        static Settings()
        { }

        public static void SetINIPath(string INIFile)
        {
            using (StreamReader settingsFile = new StreamReader(INIFile))
            {
                bool parseSuccess = true;
                string fileLine = settingsFile.ReadLine();
                int indexOfSetting = fileLine.IndexOf('=') + 1;
                inputFilePath = fileLine.Substring(indexOfSetting);
                fileLine = settingsFile.ReadLine();
                indexOfSetting = fileLine.IndexOf('=') + 1;
                outputFileName = fileLine.Substring(indexOfSetting);
                fileLine = settingsFile.ReadLine();
                indexOfSetting = fileLine.IndexOf('=') + 1;
                answersFile = fileLine.Substring(indexOfSetting);
                fileLine = settingsFile.ReadLine();
                indexOfSetting = fileLine.IndexOf('=') + 1;
                parseSuccess = int.TryParse(fileLine.Substring(indexOfSetting), out numberOfTests);
                if (!parseSuccess)
                {
                    throw new ArgumentException("Wrong number of tests");
                }
                fileLine = settingsFile.ReadLine();
                indexOfSetting = fileLine.IndexOf('=') + 1;
                parseSuccess = int.TryParse(fileLine.Substring(indexOfSetting), out questionCount);
                if (!parseSuccess || questionCount < 1)
                {
                    throw new ArgumentException("Wrong number of questions");
                }
                fileLine = settingsFile.ReadLine();
                indexOfSetting = fileLine.IndexOf('=') + 1;
                parseSuccess = int.TryParse(fileLine.Substring(indexOfSetting), out answersCount);
                if (!parseSuccess || answersCount < 2)
                {
                    throw new ArgumentException("Wrong number of answers");
                }
            }
        }
    }
}
